﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookSystem
{
    public partial class LoginMainForm : Form
    {
        public LoginMainForm()
        {
            InitializeComponent();
        }

        private void LoginMainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void LoginMainForm_Load(object sender, EventArgs e)
        {
            this.Text = string.Format("{0}登录系统", Type.type);
            if (Type.type == "管理员")
            {
                lab_AddUser.Hide();
                lab_wenAddUser.Hide();
            }
        }

        private void lab_retuen_Click(object sender, EventArgs e)
        {
            Login Loginform = new Login();
            Loginform.Show();
            this.Hide();
        }

        private void lab_LookForPswd_Click(object sender, EventArgs e)
        {
            LookForPswdForm LookForPswdForm = new LookForPswdForm();
            LookForPswdForm.Show();
            this.Hide();
        }

        private void lab_AddUser_Click(object sender, EventArgs e)
        {
            AddUsersForm AddUsersForm = new AddUsersForm();
            AddUsersForm.Show();
            this.Hide();
        }

        private void but_login_Click(object sender, EventArgs e)
        {
            string Name = this.Box_name.Text;
            string Pswd = this.Box_pswd.Text;

            if (Type.type == "管理员")
            {
                string sql = string.Format("select * from T_Admins where Name ='{0}' and pswd ='{1}'", Name, Pswd);
                if (DBHepler.SqlDataAdapter(sql).Rows.Count > 0)
                {
                    Type.name = this.Box_name.Text;

                    MainForm MainForm = new MainForm();
                    MainForm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("账号或密码输入有误呢/", "登录提示：",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
            else
            {
                string sql = string.Format("select * from T_Users where Name ='{0}' and pswd ='{1}'", Name, Pswd);
                if (DBHepler.SqlDataAdapter(sql).Rows.Count > 0)
                {
                    Type.name = this.Box_name.Text;

                    MainForm MainForm = new MainForm();
                    MainForm.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("账号或密码输入有误呢/", "登录提示：",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
        }

        private void checkBox_pswd_CheckedChanged(object sender, EventArgs e)
        {
            MessageBox.Show("该功能尚未完善/有什么想法可以分享哦", "团队**提示：",
                        MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
        }

        
    }
}
